#ifndef __GAMEHACK_GAMEHACK_H__
#define __GAMEHACK_GAMEHACK_H__
#include <windows.h>

#include "singleton.hpp"
#include "AstarFindPath.hpp"
#include "../tcc-0.9.26/libtcc.h"

typedef HWND (WINAPI* API_SetFocus)(HWND hWnd);

class GameHack :public core::singleton<GameHack>
{
	friend core::singleton<GameHack>;

private:
	GameHack()
		: dll_hadle_(NULL), is_initialized_(false), tcc_(NULL), game_wnd_handle_(NULL)
	{}

public:
	~GameHack()
	{}

public:
	bool Initialize(HINSTANCE dll_hanlde);
	void Finalize();

public:
	LRESULT KeyBoardProc(HHOOK hook_handle, int nCode,WPARAM wParam,LPARAM lParam);
	LRESULT GameWndProcHandler(WNDPROC game_wnd_proc, HWND hWnd, UINT wMsg, WPARAM wParam,LPARAM lParam);
	HWND SetFocusHandler(API_SetFocus set_focus, HWND hWnd);

private:
	void InstallInlineHook();
	void UninstallInlineHook();
	void InstallHook();
	BOOL UninstallHook();

private:
	bool InitScriptEngine();
	void RegisterFunction(TCCState* tcc);
	void FreeScriptEngine();
	void RunScript(const char* file_name);
	void ProcessCmd(std::string& cmd);

public:
	inline const char* get_dll_path() { return dll_path_.c_str(); }

private:
	HINSTANCE dll_hadle_;
	std::string dll_path_;
	bool is_initialized_;
	TCCState *tcc_;
	HWND game_wnd_handle_;
	Astar::AstarFinder astar_finder_;
	Astar::Path astar_path_;
};
#define sGameHack GameHack::get_instance()
#endif//__GAMEHACK_GAMEHACK_H__